<?php

namespace app\admin\controller;
use app\base\controller\Base;
use think\Request;
use think\Cache;
use think\Config;
use think\Session;


//处理图片上传
class Image extends Base
{
    public  $model;

    public function __construct()
    {
   $this->model = model("UsersInvest");
        parent::__construct();

    }



    public function save(){


  $file = request()->file('image');

        // 移动到框架应用根目录/public/uploads/ 目录下
        if($file){
            $uploadPath = ROOT_PATH . 'public' . DS . 'uploads';
            $uploadPathBack = '/uploads/';
            $info = $file->move($uploadPath);

            if($info){

                $name = $info->getSaveName();
                $name = str_replace("\\","/",$name);

                $data['image'] = Request::instance()->domain().$uploadPathBack.$name;
                return sucessJson("上传成功",$data);
            }

        }
        return failJson("上传失败");
    }


    /**
     * @return \think\response\Json 报价上传
     */
    public function upload(){


     $file = request()->file('key');
        // 移动到框架应用根目录/public/uploads/ 目录下
        if($file){
            $uploadPath = ROOT_PATH . 'public' . DS . 'uploads';
            $uploadPathBack = '/uploads/';
            $info = $file->move($uploadPath);
            $darrValue =["证券代码","证券名称","证券属性","15天","1个月","2个月",	"3个月","4个月","5个月","6个月"	,"7个月"	,"8个月",	"9个月",	"10个月","11个月"	,"12个月"];
            $darrKey =["code","name","attr","fifteen","one","two",	"three","four","five","six"	,"seven","eight",	"nine","ten","eleven","twelve"];
            $map = array_combine($darrKey,$darrValue);

            if($info){
               $name = $info->getSaveName();
                $name = str_replace("\\","/",$name);
                $execl = $uploadPath.DS.$name;
                $excelModel = new \tool\Excel();
                $data =   $excelModel->readExcelFile($execl,$map);
                $PriceModel = new \app\admin\model\MarkPrice();
                $res = $PriceModel->saveData($data);
                if($res['status']){
                    return sucessJson($res['msg']);
                }

            }

        }
        return failJson("上传失败");
    }








}
